<template>
	<view>
		<uni-nav-bar left-icon="left"  :statusBar="true" titleSize="30px" leftText="返回" right-text="保存" title="修改物流" @clickRight="editFn"  @clickLeft="back"  :fixed="true" backgroundColor="#3286ed" color="#fff"/>
		<u--form class="form" labelPosition="left" labelWidth="100px" :model="form"  ref="form">
			<u-form-item  label="租赁订单" prop="orderNo" borderBottom ref="item1" @click="openPop">
				<u--input :readonly="true" v-model="form.orderNo" border="none" placeholder="选择租赁订单"></u--input>
							<u-icon @click="openPop" slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item  label="仓库名" prop="warehouseName" borderBottom ref="item1">
				<u--input :readonly="true" v-model="form.warehouseName" border="none" placeholder="仓库名"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item  label="出库单编号" prop="outboundNo" borderBottom ref="item1">
				<u--input :readonly="false" v-model="form.outboundNo" border="none" placeholder="出库单编号"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item  label="回货申请单编号" prop="returnApplyNo" borderBottom ref="item1">
				<u--input :readonly="false" v-model="form.returnApplyNo" border="none" placeholder="回货申请单编号"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item @click="typeShow=true"  label="出入库类型" prop="type" borderBottom ref="item1">
				<u--input :readonly="true" v-model="form.type" border="none" placeholder="出入库类型"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item  label="项目名称" prop="projectName" borderBottom ref="item1">
				<u--input :readonly="true" v-model="form.projectName" border="none" placeholder="项目名称"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item  label="目的地" prop="projectAddress" borderBottom ref="item1">
				<u--input :readonly="true" v-model="form.projectAddress" border="none" placeholder="目的地"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item @click="logisticsShow=true"  label="运输方式" prop="logisticsType" borderBottom ref="item1">
				<u--input :readonly="true" v-model="form.logisticsType" border="none" placeholder="选择运输方式"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item  label="司机名称" prop="driverName" borderBottom ref="item1">
				<u--input v-model="form.driverName" border="none" placeholder="请输入司机名称"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item  label="司机联系方式" prop="driverTel" borderBottom ref="item1">
				<u--input v-model="form.driverTel" border="none" placeholder="司机联系方式"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item  label="车辆信息" prop="vehicleInformation" borderBottom ref="item1">
				<u--input v-model="form.vehicleInformation" border="none" placeholder="车辆信息"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item  label="识别信息" prop="serialNumber" borderBottom ref="item1">
				<u--input v-model="form.serialNumber" border="none" placeholder="若是第一次出库物流则为数字1,以此类推"></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item  label="物流费用" prop="logisticsExpenses" borderBottom ref="item1">
				<u--input v-model="form.logisticsExpenses" border="none" placeholder="物流费用"></u--input>
							<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
			</u-form-item>
			<u-form-item @click="arrivalDateShow=true"  label="到货日期" prop="arrivalDate" borderBottom ref="item1">
				<u--input v-model="form.arrivalDate" border="none" placeholder="到货日期"></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			 
		</u--form>
		<!-- 提示框 -->
			<u-modal showConfirmButton showCancelButton @confirm="BtnModel" width='250px'  @cancel="BtnShow=false" :show="BtnShow" title="提示" >
					<view class="slot-content">
						<rich-text nodes="是否确认提交?"></rich-text>
					</view>
			</u-modal>
			<u-toast ref="uToast"></u-toast>
		<u-datetime-picker :closeOnClickOverlay="true" @close="arrivalDateShow=false"
			    :show="arrivalDateShow" v-model="dateNow" @confirm="arrivalDateConfirm"
			    @cancel="arrivalDateShow=false" mode="date"></u-datetime-picker>
		
		<u-picker :closeOnClickOverlay="true" @close="logisticsShow=false" @cancel="logisticsShow=false" @confirm="logisticsConfirm" :show="logisticsShow" :columns="LogisticsOptions" keyName="dictLabel"></u-picker>
		<u-picker :closeOnClickOverlay="true" @close="typeShow=false" @cancel="typeShow=false" @confirm="typeConfirm" :show="typeShow" :columns="typeOptions" keyName="dictLabel"></u-picker>
	</view>
</template>

<script>
	import {getDicts} from '@/api/dictionary/index.js'
	import {editLogisticsApi} from "@/api/logistics.js"
	export default {
		data() {
			return {
				form:{
					type:' ',
					logisticsType:' '
				},
				dateNow:Number(new Date()),//当前时间
				arrivalDateShow:false,//时间弹框
				LogisticsOptions:[],
				options1:[],
				logisticsShow:false,
				typeShow:false,
				typeOptions:[],
				option2:[],
				BtnShow:false
				
			};
		},
		async onLoad(e) {
			this.form= JSON.parse(decodeURIComponent(e.item))
			await this.getLogisticsList()
			await this.gettypeOptions()
			this.form.type=this.getValue(this.option2,this.form.orderProperty)
			this.form.logisticsType=this.getValue(this.options1,this.form.shippingType)
			
			console.log(this.form.logisticsType);
			console.log(this.dateNow);
			
		},
	  created() {
			
		},
		methods:{
			getValue(arr, item) {
			      for (let i = 0; i < arr.length; i++) {
			        if (item === arr[i].dictValue) {
			          return arr[i].dictLabel
			        }
			      }
			    },
			// 获取当前时间
			getNowTime() {
			    var date = new Date()
			    var month = date.getMonth() + 1;
			    var time = date.getFullYear() + "-" + month + "-" + date.getDate();
			    return time;
			},
			// 时间格式化
			getTime(val) {
			    var date = new Date(val);
			    var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
			    var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
			    var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
			    //修改月份格式
			    if (month >= 1 && month <= 9) {
			        month = "0" + month;
			    }
			    //修改日期格式
			    if (day >= 0 && day <= 9) {
			        day = "0" + day;
			    }
			    var currentFormatDate = `${year}-${month}-${day}`;
			    return currentFormatDate
			},
			// 实际到货时间
			arrivalDateConfirm(e) {
			    console.log(e);
			    this.form.arrivalDate = this.getTime(e.value)
			    this.arrivalDateShow = false
			},
			//获取物流运输方式
			    async getLogisticsList(){
			      let res=await getDicts('biz_shipping_type')
			      this.LogisticsOptions.push(res.data)
				  this.options1=res.data
			    },
				logisticsConfirm(val){
					this.logisticsShow=false
					this.form.shippingType=val.value[0].dictValue
					this.form.logisticsType=val.value[0].dictLabel
				},
				//出入库类型
				async gettypeOptions(){
				  let res=await getDicts('out_return_type')
				  this.typeOptions.push(res.data)
				  this.option2=res.data
				},
				typeConfirm(val){
					this.typeShow=false
					this.form.orderProperty=val.value[0].dictValue
					this.form.type=val.value[0].dictLabel
				},
				back(){
					uni.navigateBack({
						 delta:1
					})
				},
				editFn(){
					  this.BtnShow=true
				},
				async BtnModel(){
					this.BtnShow=false
				    await editLogisticsApi(this.form)
					
					this.$refs.uToast.show({
						type:'success',
						message:"修改成功",
						complete(){
							uni.navigateTo({
								url:"/pages/logistics/details/index?id="+this.form.id
							})
					        // uni.navigateBack({delta:1})
						}
					})
				}
				
		}
	}
</script>

<style lang="scss">
.form{
	background-color: #fff;
	padding-left: 15px;
}
</style>
